/**
 * 单曲播放显示
 */
var SongCanPlay = false;
var LRCFlag = false;

(function() {
	'use strict';

	var filename = "templates/radio/songInfo.txt";

	//var templateHTML = gm.io.readFile(filename);
	var templateHTML = '<div id="currentInfo"><div>频道:<span id="currentChannelName"></span></div><div>歌曲名:<span id="currentSongName">{{songinfo.title}}</span></div><div>歌手:<span id="currentSongArtist">{{songinfo.author}}</span></div><div>播放时间:<span id="currentSongStatus"></span></div></div><div id="favouriveBtn" class="btn">收藏</div><div id="playBtn" class="btn">播放</div><div id="nextSongBtn" class="btn">下一首</div><div id="songCover" style="background-image: url({{songinfo.pic_big}}); background-size: 100%;"></div>';
	CCR.Views.SongInfoView = Backbone.View.extend({ // 单曲信息视图
	el : 'div#songInfo', // 模板根元素
	template : Handlebars.compile(templateHTML), // 模板
	events : {
		// debug view
		/*
		"rotaryBlur .btn" : "buttonRotaryBlur",
			"rotaryFocus .btn" : "buttonRotaryFocus",
			"rotarySelect .btn" : "buttonRotarySelect",
			"mouseup .btn" : "buttonRotarySelect", 
			*/
	},
	// 事件处理函数：进入焦点
	buttonRotaryFocus : function(e) {
		$(e.target).addClass("focus");
	},
	buttonRotaryBlur : function(e) {
		$(e.target).removeClass("focus");
	},
	buttonRotarySelect : function(e) {
		var self = this;
		$(e.target).addClass("selected");
		setTimeout(function() {
			$(e.target).removeClass("selected");
			var targetId = $(e.target).attr("id");
			switch (targetId) {
				case "favouriveBtn": //收藏 按钮
					//TODO
					
				break;
				case "playBtn":	//播放/暂停 按钮
					//TODO
					CCR.Media.pause();
				break;
				case "nextSongBtn":	//下一首按钮
					//TODO
				break;
			}
		}, 100);
	},
	// 显示
	show : function() {
		this.hidden = false;
		this.render();
	},

	// 隐藏
	hide : function() {
		if (!this.hidden) {
			this.hidden = true;
			this.$el.html("");
		}
	},

	// 渲染
	render : function(song_id) {
		var self = this;
				CCR.Songs.getSongInfo(song_id, function(songinfo) {
					self.$el.html(self.template({ songinfo : songinfo.songinfo }));
					//显示频道名称
					$("#currentChannelName").html(CCR.Songs.channellInfo_name);
					
					//绑定按钮事件
					//收藏
					$("#favouriveBtn").unbind("rotaryBlur").bind("rotaryBlur",function(){
						$(this).removeClass("focus");
					}).unbind("rotaryFocus").bind("rotaryFocus",function(){
						$(this).addClass("focus");
					}).unbind("rotarySelect mouseup").bind("rotarySelect mouseup",function(){
						var self = this;
						$(self).addClass("selected");
						setTimeout(function(){
							$(self).removeClass("selected");
							if($(self).html()==="收藏"){
								//Problem navigate引导同一个url时无效
								CCR.Router.navigate('#addFavoriteSong/' + song_id, true);		
							}else{
								CCR.Router.navigate('#deleteFavoriteSong/' + song_id, true);	
							}
										
						},100);
					});
					
					//播放/暂停
					$("#playBtn").unbind("rotaryBlur").bind("rotaryBlur",function(){
						$(this).removeClass("focus");
					}).unbind("rotaryFocus").bind("rotaryFocus",function(){
						$(this).addClass("focus");
					}).unbind("rotarySelect mouseup").bind("rotarySelect mouseup",function(){
						var self = this;
						$(self).addClass("selected");
						setTimeout(function(){
							$(self).removeClass("selected");
							CCR.Media.pause();
						},100);
					});
					//下一首
					$("#nextSongBtn").unbind("rotaryBlur").bind("rotaryBlur",function(){
						$(this).removeClass("focus");
					}).unbind("rotaryFocus").bind("rotaryFocus",function(){
						$(this).addClass("focus");
					}).unbind("rotarySelect mouseup").bind("rotarySelect mouseup",function(){
						var self = this;
						$(self).addClass("selected");
						setTimeout(function(){
							$(self).removeClass("selected");
							CCR.Media.stop();
							CCR.SongList.playNext(CCR.Songs);
						},100);
					});
					
					//重新绑定旋钮
					Rotary.fresh();	//绑定旋钮fresh
//				});	
//			}else{
//				log("获取频道歌曲列表长度为0");
//			}
			
		});
	},

	initialize : function(options) {
		if (options) {
			this.render(options.song_id);
		}
	},

	});

})();
